﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using ArtClub.Controller;
using ArtClub.Model;

namespace UI
{
	/// <summary>
	/// Interaction logic for CreateMember.xaml
	/// </summary>
    public partial class CreateMember : UserControl
    {
        #region fields
        private MemberCtr memberCtr = new MemberCtr();
        private Member member = new Member();
        #endregion

        public CreateMember()
        {
            InitializeComponent();
            PopulateLists();
        }

        private void PopulateLists()
        {
            ListMember.ItemsSource = null;

            ListMember.ItemsSource = memberCtr.ListMembers();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                member.Name = textboxName.Text;
                member.Division = textboxDepartment.Text;
                member.Address = textboxAddress.Text;
                member.Email = textboxMail.Text;
                member.PostalCode = int.Parse(textboxZipcode.Text);
                member.SSN = textboxSocialSecurityNr.Text;
                member.City = textboxCity.Text;
                member.Telephone = long.Parse(textboxMobilPhone.Text);
                member.CreationDate = DateTime.Now;

                memberCtr.CreateMember(member);
                PopulateLists();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //Grim kode
            Auction a = new Auction();
            a.UpdateMemberList();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            textboxName.Clear();
            textboxDepartment.Clear();
            textboxAddress.Clear();
            textboxMail.Clear();
            textboxZipcode.Clear();
            textboxSocialSecurityNr.Clear();
            textboxCity.Clear();
            textboxMobilPhone.Clear();
        }


            
    }

}
